package com.itheima.interceptor;

import com.itheima.domain.User;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class ResourcesInterceptor extends HandlerInterceptorAdapter {
    /*private List<String> ignoreUrl;

    public ResourcesInterceptor(List<String> ignoreUrl) {
        this.ignoreUrl = ignoreUrl;
    }*/

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User)request.getSession().getAttribute("USER_SESSION");
        String uri = request.getRequestURI();
        if (user != null) {
                return true;
        }

        if (uri.indexOf("login") >= 0) {
            return true;
        }
            request.setAttribute("msg", "您还没有登录，请先登录！");
            request.getRequestDispatcher("/admin/login.jsp").forward(request, response);
            return false;

    }
}
